//package com.reliable.service.controller;
//
//import java.io.IOException;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.reliable.api.param.IdParam;
//import com.reliable.common.core.domain.AjaxResult;
//import com.reliable.service.domain.ReliableImage;
//import com.reliable.service.oss.service.OssService;
//import com.reliable.service.service.IReliableImageService;
//import com.reliable.service.utils.IdEncryptUtils;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.*;
//import org.springframework.web.multipart.MultipartFile;
//
///**
// * reliable图片URL存储Controller
// *
// * @author ruoyi
// * @date 2025-07-09
// */
//@RestController
//@RequestMapping("/reliable/image")
//@Api(value = "reliable图片控制器", tags = {"reliable图片管理"})
//public class ReliableImageController {
//
//    @Autowired
//    private IReliableImageService reliableImageService;
//
//    @Autowired
//    private OssService ossService;
//
//    /**
//     * 查询reliable图片列表,根据任务ID
//     */
//    @ApiOperation("查询reliable图片列表,根据任务ID")
//    @PostMapping("/ImagesList")
//    public AjaxResult list(@RequestBody IdParam param) {
//        // 避免修改原始参数
//        Long decryptedId;
//        try {
//            decryptedId = IdEncryptUtils.decrypt(param.getBusinessId());
//        } catch (Exception e) {
//            return AjaxResult.error("解密 businessId 失败");
//        }
//
//        LambdaQueryWrapper<ReliableImage> queryWrapper = new LambdaQueryWrapper<>();
//        List<ReliableImage> data = reliableImageService.list(queryWrapper.eq(ReliableImage::getTaskId, decryptedId));
//
//        if (data.isEmpty()) {
//            LambdaQueryWrapper<ReliableImage> statusQueryWrapper = new LambdaQueryWrapper<>();
//            List<ReliableImage> data1 = reliableImageService.list(statusQueryWrapper.eq(ReliableImage::getImageStatus, 2)); // 建议改为常量
//            processImagesForResponse(data1, false);
//            return AjaxResult.success(data1);
//        }
//
//        processImagesForResponse(data, true);
//        return AjaxResult.success(data);
//    }
//
//    private void processImagesForResponse(List<ReliableImage> images, boolean includeTaskBusinessId) {
//        for (ReliableImage image : images) {
//            image.setBusinessId(IdEncryptUtils.encrypt(image.getId()));
//            if (includeTaskBusinessId && image.getTaskId() != null) {
//                image.setTaskBusinessId(IdEncryptUtils.encrypt(image.getTaskId()));
//            }
//            image.setId(null);
//            image.setTaskId(null);
//        }
//    }
//
//
//    /**
//     * 获取reliable图片详细信息
//     */
//    @ApiOperation("获取reliable图片详细信息")
//    @PostMapping("/ImageInfo")
//    public AjaxResult info(@RequestBody IdParam  param) {
//        param.setId(IdEncryptUtils.decrypt(param.getBusinessId()));
//        ReliableImage entity = reliableImageService.getById(param.getId());
//        entity.setBusinessId(IdEncryptUtils.encrypt(entity.getId()));
//        entity.setTaskBusinessId(IdEncryptUtils.encrypt(entity.getTaskId()));
//        entity.setId(null);
//        entity.setTaskId(null);
//        return AjaxResult.success(entity);
//    }
//
//
//    @ApiOperation("文件上传")
//    @PostMapping("/uploadFile")
//    public AjaxResult uploadFile(@RequestParam("file")MultipartFile file) {
//        Map<String, Object> result = new HashMap<>();
//        try {
//            String url = ossService.uploadFile(file);
//            result.put("success", true);
//            result.put("url", url);
//            result.put("message", "上传成功");
//        } catch (Exception e) {
//            result.put("success", false);
//            result.put("message", e.getMessage());
//        }
//        return AjaxResult.success( result);
//    }
//
//    /**
//     * base64图片上传测试
//     * @return
//     */
//
//    @PostMapping("/saveImage")
//    public AjaxResult saveImage(@RequestParam("image64") String image64) throws IOException {
//        String url = ossService.uploadBase64Image(image64);
//        return AjaxResult.success(url);
//    }
//
//
//}
